package GreedyThought;

// Lettcode 605: https://leetcode-cn.com/problems/can-place-flowers/
public class canPlaceFlowers {
    public boolean canPlaceFlowers(int[] flowerbed, int n) {
        if (flowerbed == null || flowerbed.length < 2*n - 1) return false;
        int count = 0;
        for (int i = 0; i < flowerbed.length && count < n; i++) {
            if (flowerbed[i] == 1) {
                continue;
            }
            int pre = i == 0? 0 : flowerbed[i-1];
            int next = i == flowerbed.length - 1? 0 : flowerbed[i + 1];
            if (pre == 0 && next == 0) {
                count++;
                flowerbed[i] = 1;
            }
            if (count >= n) {
                return true;
            }
        }
        Man man = new Man(20, 30);
        System.out.println(man.getlength());
        return false;
    }

    private class Man {
        int height;
        int args;
        int getlength() {
            return this.height;
        }
        Man(int height, int args) {
            this.height = height;
            this.args = args;
        }
    }
}
